package jp.tkym.labs.m3d;

import java.beans.PropertyChangeListener;

/**
 * 3D Modeling class for Swing Component
 * @author kazunari
 */
public class DrawableBinder <D extends Draw>{
	private final Drawable<D> drawable;
	private final Camera3D camera;
	private ModelConverter converter;
	private D background;
	
	public DrawableBinder(Drawable<D> canvas, ModelConverter converter, Camera3D camera){
		this.drawable = canvas;
		this.camera = camera;
		this.converter = converter;
	}
	
	public void setBackground(D drawBackGround){
		this.background = drawBackGround;
	}
	
	@SuppressWarnings("unchecked")
	public void sync(){
		drawable.drawList().clear();
		if(background != null)
			drawable.drawList().add(background);
		for(Draw drawing: camera.draw(converter)) 
			drawable.drawList().add((D)drawing);
	}
	
	public void addPropertyChangeListener(PropertyChangeListener listener){
		this.drawable.addPropertyChangeListener(listener);
	}
}